package ch.usi.inf.pf2.editor;

import javax.swing.border.Border;

import ch.usi.inf.pf2.Sheet;

/**
 * MultipleChangeCellBorder is useful to change the
 * border of more cells.
 * 
 * @author Ebrisa Savina Mastrodicasa
 */


public class MultipleChangeCellBorder extends CellManagement
{
	private ChangeCellBorder[][] toChange;
	
	
	/**
	 * Create a ChangeCellBorder for more cells.
	 * @param s The sheet where the multiple changing of border is performed.
	 * @param rowIndex The rows of the selected cells.
	 * @param columnIndex The columns of the selected cells.
	 * @param newBorder The border type to be applied to the selected cells.
	 */
	public MultipleChangeCellBorder(Sheet s, int[] rowIndexes, int[] columnIndexes, Border newBorder)
	{
		toChange = new ChangeCellBorder[rowIndexes.length][columnIndexes.length];
		for(int i=0; i<rowIndexes.length; i++)
			  for(int j=0; j<columnIndexes.length; j++)
				 toChange[i][j]=new ChangeCellBorder(s, rowIndexes[i]+1, columnIndexes[j]+1, newBorder);
	}
	
	
	/**
	 * Apply the ChangeCellBorder to all the selected cells.
	 */
	public void evaluate() {
		for(int i = 0; i < toChange.length; i++)
			for(int j = 0; j < toChange[i].length; j++)
			{
				toChange[i][j].evaluate();
			}
	}

	
	/**
	 * Restore the previous border type of the selected cells.
	 */
	public void restore() {
		for(int i=0; i<toChange.length; i++)
			  for(int j=0; j<toChange[i].length; j++)
				 toChange[i][j].restore();
	}

}
